package com.isyscore.util;

import com.alibaba.fastjson.JSON;
import com.isyscore.vo.ResponseVo;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletResponse;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: liuxq@isyscore.com
 * @Date: 2021-04-16 09:39:30
 * @Description: 返回结果工具类
 */
@Slf4j
public class ResultUtil {

    /**
     * 私有化构造器
     */
    private ResultUtil() {
    }

    /**
     * 使用response输出JSON
     *
     * @Param resultMap 数据
     * @Return void
     */
    public static void responseJson(ServletResponse response, ResponseVo vo) {
        PrintWriter out = null;
        try {
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json");
            out = response.getWriter();
            out.println(JSON.toJSONString(vo));
        } catch (Exception e) {
            log.error("【JSON输出异常】" + e);
        } finally {
            if (out != null) {
                out.flush();
                out.close();
            }
        }
    }

}
